package com.lxj.stream;

/**
 * TestCode
 */
public class TestCode {

    public static void main(String[] args) {
        String str = "中";
        showCode(str);
        
    }

    private static void showCode(String str) {
        String[] encodes = {"BIG5", "GBK","GB2312","UTF-8","UTF-16","UTF-32"};
        for (String ec : encodes) {
            showCode(str, ec);
        }
    }

    private static void showCode(String str, String encode) {
        try {
            System.out.printf("字符:\"%s\" 在编码方式%s下的十六进制是%n",str, encode);
            byte[] bs = str.getBytes(encode);

            for (byte b : bs) {
                int i = b&0xff;
                System.out.println(Integer.toHexString(i));
            }
            System.out.println();
            System.out.println();
        } catch (Exception e) {
            e.printStackTrace();
            //TODO: handle exception
        }
    }
}